package com.syni.mdd.sjb.tool.controller.protect;

import com.syni.mdd.sjb.common.component.utils.common.utils.CDNUtils;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import com.syni.mdd.sjb.tool.entity.vo.BaseRqVo;
import com.syni.mdd.sjb.tool.entity.vo.responseVo.DataTreasureVersionRpVo;
import com.syni.mdd.sjb.tool.enums.CdnEnums;
import com.syni.mdd.sjb.tool.service.CommonToolService;
import com.syni.mdd.sjb.tool.service.impl.CommonToolServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class ToolCommonController {

    @Autowired
    CommonToolService commonToolService;

    @GetMapping("/cdn/uploadSignature")
    @ApiOperation(value = "获取服务端图片上传签名")
    public Map<String,Object> uploadSignature(@RequestBody BaseRqVo baseRqVo){
        JSONObject jsonObject = CDNUtils.getUploadSignature();
        JSONObject credentials = jsonObject.optJSONObject("credentials");
        if(credentials != null){
            return ResultMapHelper.success(credentials.toMap());
        }
        return ResultMapHelper.result(CdnEnums.GET_UPLOAD_SIGNATURE_FAIL);
    }

    @GetMapping("/common/getDataTreasureVersion")
    @ApiOperation(value = "获取数据宝最新版本号")
    public Map<String,Object> getDataTreasureVersion(){
        DataTreasureVersionRpVo dataTreasureVersionRpVo = new DataTreasureVersionRpVo();
        CommonToolServiceImpl commonToolServiceImpl = (CommonToolServiceImpl) commonToolService;
        DataTreasureVersionRpVo.IosVersionData iosVersionData = new DataTreasureVersionRpVo.IosVersionData();
        iosVersionData.setMajorNum(commonToolServiceImpl.getDataTreasureVerionConfig().getIos_majorNum());
        iosVersionData.setMinorNum(commonToolServiceImpl.getDataTreasureVerionConfig().getIos_minorNum());
        iosVersionData.setRevisionNum(commonToolServiceImpl.getDataTreasureVerionConfig().getIos_revisionNum());
        iosVersionData.setBuildNum(commonToolServiceImpl.getDataTreasureVerionConfig().getIos_buildNum());
        iosVersionData.setIsUpdateMandatory(commonToolServiceImpl.getDataTreasureVerionConfig().getIos_isUpdateMandatory());
        iosVersionData.setUpdateDesc(dataTreasureVersionRpVo.handleDescText(commonToolServiceImpl.getDataTreasureVerionConfig().getIos_updateDesc()));
        dataTreasureVersionRpVo.setIosVersionData(iosVersionData);

        //安卓配置
        DataTreasureVersionRpVo.AndVersionData andVersionData = new DataTreasureVersionRpVo.AndVersionData();
        andVersionData.setMajorNum(commonToolServiceImpl.getDataTreasureVerionConfig().getAnd_majorNum());
        andVersionData.setMinorNum(commonToolServiceImpl.getDataTreasureVerionConfig().getAnd_minorNum());
        andVersionData.setRevisionNum(commonToolServiceImpl.getDataTreasureVerionConfig().getAnd_revisionNum());
        andVersionData.setBuildNum(commonToolServiceImpl.getDataTreasureVerionConfig().getAnd_buildNum());
        andVersionData.setIsUpdateMandatory(commonToolServiceImpl.getDataTreasureVerionConfig().getAnd_isUpdateMandatory());
        andVersionData.setUpdateDesc(dataTreasureVersionRpVo.handleDescText(commonToolServiceImpl.getDataTreasureVerionConfig().getAnd_updateDesc()));
        dataTreasureVersionRpVo.setAndVersionData(andVersionData);
        return ResultMapHelper.success(dataTreasureVersionRpVo);
    }


}
